#ifndef __OLED_H_
#define __OLED_H_

#include "stm32f4xx.h"

/*颜色设置*/
typedef struct{
	u16 RGB;
}OLED_COLOR;

/*横屏还是竖屏*/
typedef enum {
	OLED_flip0,			//竖屏
	OLED_flip90,		//翻转90
	OLED_flip180,		//翻转180
	OLED_flip270		//翻转270
}According;

/*屏幕基本信息*/
typedef struct{
	u16 OLED_Width;
	u16 OLED_Hight;
	u16 OLED_X;
	u16 OLED_Y;
	According OLED_Der;
}OLED_INFO;

#define OLED_Port GPIOB
#define OLED_RES GPIO_Pin_6		//复位引脚
#define OLED_BLK GPIO_Pin_7		//背光
#define OLED_DC GPIO_Pin_8		//数据/命令引脚
#define OLED_CS GPIO_Pin_9    //片选信号
/*
	BSRRH 表示BSRR寄存器高16位（BRy），哪一个BRy置1，引脚输出低电平；
	BSRRL 表示BSRR寄存器低16位（BSy），哪一个BRy置1，引脚输出高电平；
*/
#define OLED_CS_ENABLE GPIOB->BSRRH = OLED_CS;		//开启片选
#define OLED_CS_DISABLE GPIOB->BSRRL = OLED_CS;		//关闭片选
#define OLED_RES_ENABLE GPIOB->BSRRH = OLED_RES;		//开启复位
#define OLED_RES_DISABLE GPIOB->BSRRL = OLED_RES;		//关闭复位
#define OLED_instruction GPIOB->BSRRH = OLED_DC;		//指令
#define OLED_data GPIOB->BSRRL = OLED_DC;		//数据
#define OLED_BLK_ENABLE GPIOB->BSRRH = OLED_BLK;		//开启背光
#define OLED_BLK_DISABLE GPIOB->BSRRL = OLED_BLK;		//关闭背光
/*库函数控制*/
//#define OLED_CS_ENABLE GPIO_ResetBits(GPIOB,OLED_CS);		//开启片选
//#define OLED_CS_DISABLE GPIO_SetBits(GPIOB,OLED_CS);		//关闭片选
//#define OLED_RES_ENABLE GPIO_ResetBits(GPIOB,OLED_RES);		//开启复位
//#define OLED_RES_DISABLE GPIO_SetBits(GPIOB,OLED_RES);		//关闭复位
//#define OLED_instruction GPIO_ResetBits(GPIOB,OLED_DC);		//指令
//#define OLED_data GPIO_SetBits(GPIOB,OLED_DC);		//数据
//#define OLED_BLK_ENABLE GPIO_ResetBits(GPIOB,OLED_BLK);		//开启背光
//#define OLED_BLK_DISABLE GPIO_SetBits(GPIOB,OLED_BLK);		//关闭背光
/**
	oled屏幕信息定义
*/
#define OLED_H 128
#define OLED_W 128
/*各种命令宏的定义*/
#define OLED_NOP 0X00
#define OLED_WriteGRAMCmd 0x2C			//写GRAM指令
#define OLED_SetXCmd 0x2A					//设置x坐标指令
#define OLED_SetYCmd 0x2B					//设置y坐标指令
#define OLED_APPReSet 0x01 			//软件复位指令

void Set_X(u16 x);
void Set_Y(u16 y);
void Set_X_Y(u16 x,u16 y);
void OLED_ReSet(void);
void OLED_WriteCmd(u16 cmd);
void OLED_WriteData(u8 data);
void OLED_WriteData16Bit(u16 data);
void OLED_WriteReg(u8 OLED_Reg, u16 OLED_RegValue);
void OLED_DisplayConifig(According Angle);
void OLED_Init(void);
void OLED_SetWindows(u8 startx,u8 starty,u8 endx,u8 endy);
void OLED_Clear(u16 color);
void OLED_Cursor(u8 x,u8 y);
void OLED_SetDraw(u8 x,u8 y);
void OLED_SetColorDraw(u8 x,u8 y,u16 color);
#endif
